﻿
Partial Class Programmed
    Inherits System.Web.UI.Page
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim sb As New System.Text.StringBuilder
        For Each item As WebControls.ListItem In ListBox1.Items
            If item.Selected Then
                sb.Append(item.Value)
                sb.Append(",")
            End If
        Next
        Dim moires As String = sb.ToString
        If moires.Length > 0 Then
            moires = Left(moires, moires.Length - 1)
            sqldsProgrammed.FilterExpression = "id_Moira in (" + moires + ")"
        Else
            sqldsProgrammed.FilterExpression = "--"
        End If
    End Sub

    Protected Sub btnInsert_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnInsert.Click
        GridView1.ShowFooter = True
        'sqldsStaff.Insert()
    End Sub

    Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
        General.FilterBySquadron(sqldsStaff, ListBox1)
        Select Case e.CommandName
            Case "New"
                For Each x As WebControls.Parameter In sqldsProgrammed.InsertParameters
                    Dim ctrl As Web.UI.Control
                    Dim value As String = ""

                    ctrl = GridView1.FooterRow.FindControl("txt" & x.Name)
                    If ctrl IsNot Nothing Then value = CType(ctrl, TextBox).Text
                    ctrl = GridView1.FooterRow.FindControl("ddl" & x.Name)
                    If ctrl IsNot Nothing Then value = CType(ctrl, DropDownList).SelectedValue
                    If value <> "" Then x.DefaultValue = value
                Next
                sqldsProgrammed.Insert()
                GridView1.ShowFooter = False
            Case "CancelNew"
                GridView1.ShowFooter = False
        End Select
    End Sub

End Class
